<%@page import="net.sf.json.JSONArray"%>
<%@page import="com.chauncy.DMS.bean.StuDormInfoBean"%>
<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="./layui/css/layui.css" />
		<script type="text/javascript" src="./jquery-3.3.1/jquery-3.3.1.js" ></script>
		<script type="text/javascript" src="./jquery-3.3.1/jquery-3.3.1.min.js" ></script>
	</head>
	<%
		ServletContext sc  = request.getSession().getServletContext();
		List<Map<String,Object>> allAttList  = (List)sc.getAttribute("allAttJson");
		//System.out.println(allAttList);
		String name = null;
		String sNumber = null;
		String attDate = null;
		int attID = 0;
		if(allAttList != null){
			for(Map<String,Object> map : allAttList){
				for(String key : map.keySet()){
					if("name".equals(key)){
						name = (String)map.get(key);
					}else if("sNumber".equals(key)){
						sNumber = (String)map.get(key);
					}else if("Att_date".equals(key)){
						attDate = (String)map.get(key);
					}else if("AttId".equals(key)){
						attID = Integer.parseInt(map.get("AttId").toString());
					}
				}
			}
			System.out.println(name);
			System.out.println(sNumber);
			System.out.println(attDate);
		}else{
			System.out.print("is null");
		}
		
	 %>
	<body>
		<div class="layui-container">
			<div class="layui-row">
				<fieldset class="layui-elem-field layui-field-title">
					<legend>考勤信息</legend>
				</fieldset>
				<form class="layui-form layui-layer-iframe" id="updataAttForm">
					<div class="layui-form-item">
						<label class="layui-form-label">学生姓名:</label>
						<div class="layui-input-inline">
							<input type="text" name="name" class="layui-input" lay-verify="required" autocomplete="off" disabled="disabled" value="<%=name%>"/>
						</div>
						<label class="layui-form-label">考勤ID:</label>
						<div class="layui-input-inline">
							<input type="text" name="AttId" class="layui-input" lay-verify="required" autocomplete="off" disabled="disabled" value="<%=attID%>"/>
						</div>
						<label class="layui-form-label">学生学号:</label>
						<div class="layui-input-inline">
							<input type="text" name="sNumber" class="layui-input" lay-verify="required" autocomplete="off" disabled="disabled" value="<%=sNumber%>"/>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label" >请假记录:</label>
						<div class="layui-input-block">
							<select name='qingjia' lay-filter="qingjia" id="qingjia" lay-verify="required">
								<option value="">请选择</option>
								<option value="0">正常</option>
								<option value="1">异常</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">请假时间:</label>
						<div class="layui-input-block">
							<input type="text" name="qingjiaTime" id="qingjiaTime" class="layui-input" lay-verify="required" autocomplete="off" placeholder="请输入请假周期"/>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">晚归记录:</label>
						<div class="layui-input-block">
							<select name='wangui' lay-filter="wangui" lay-verify="required" id="wangui">
								<option id="id" value="">请选择</option>
								<option value="0">正常</option>
								<option value="1">异常</option>
								
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">晚归时间:</label>
						<div class="layui-input-block">
							<input  type="text" name="wanguiTime" id="wanguiTime" class="layui-input" lay-verify="required" autocomplete="off" placeholder="请输入签到时间"/>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">未归记录:</label>
						<div class="layui-input-block">
							<select name='weigui' lay-filter="weigui" lay-verify="required">
								<option value="">请选择</option>
								<option value="0">正常</option>
								<option value="1">异常</option>
							</select>
						</div>
					</div>
					
					
					<div class="layui-form-item">
						<label class="layui-form-label">考勤日期:</label>
						<div class="layui-input-block">
							<input name='kaoqinTime' lay-filter="kaoqin" lay-verify="required" disabled="disabled" class="layui-input" value="<%=attDate%>"/>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">文本域</label>
    					<div class="layui-input-block">
      						<textarea name="remarks" id="remarks"  placeholder="请输入内容" class="layui-textarea"></textarea>
   						</div>
					</div>			
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit lay-filter="updateAttInfo">修改</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script type="text/javascript" src="./layui/layui.js"></script>
		<script type="text/javascript">
			//layui 模块初始化
			layui.use(['form','layer'], function(){
			//获取模块对象
	  			var form = layui.form
	  			,layer = layui.layer;
				//监听请假记录select	
				form.on('select(qingjia)',function(data){
					console.log((data.value));
					//select value = 1 表示请假有异常记录(有请假记录) value = 0 表示无异常记录(无请假记录)
					if(data.value == 1){
						//开启请假时间的输入功能
						$('#qingjiaTime').removeAttr('disabled','disabled');
						$('#qingjiaTime').val("");
					}else{
						//请假时间input 禁用
						$('#qingjiaTime').attr('disabled','disabled');
						$('#qingjiaTime').val("无");
					}
				});
				//监听晚归select 功能如上
				form.on('select(wangui)',function(data){
					console.log((data.value));
					if(data.value == 1){
						$('#wanguiTime').removeAttr('disabled','disabled');
						$('#wanguiTime').val("");
					}else{
						$('#wanguiTime').attr('disabled','disabled');
						$('#wanguiTime').val("无");
					}
				});
				//监听未归select 
				form.on('select(weigui)',function(data){
					console.log((data.value));
				});
				//监听提交按钮 点击提交 调用updateAttInfo(obj) obj为form提交内容(类型[key:value]) 
				form.on('submit(updateAttInfo)',function(data){
					var obj = data.field;
					obj = JSON.stringify(obj);
					console.log("obj:"+obj);
					updateAttInfo(obj);
					return false;//关闭form提交功能
				});
			});
			//获取当前弹出层index
			var mainIndex = parent.layer.getFrameIndex(window.name);
			
			//更新单个学生AttInfo  param:obj 需要更新的info
			function updateAttInfo(obj){
				$.ajax({
					type:"post",
					url:"updataAloneAttInfoServlet",
					async:false,
					data:{obj:obj},
					success :function(data){		
                			if(data == 1){
								layer.open({
								time:2000,
								content:"更新成功，将在2s后关闭表单！",
								end:function(index){
									parent.layer.close(mainIndex);
								}
							});
						}
                			
					},
					error : function(xhr, status, errMsg){
						console.log("xhr"+xhr+"status:"+status+"errMsg:"+errMsg);
					}
				});
			}
			
		</script>
	</body>
</html>
